from django.shortcuts import render, HttpResponse
from django.http import JsonResponse


# Create your views here.
def index(request):
    return HttpResponse('这是app01的index页面')
    # pass


def devops(request):
    # 把信息输出到命令行
    # 属性
    # request 是客户端 请求信息封装对象
    print(request.scheme)
    # print(request.method)
    # print(request.body)
    # print(request.path)
    # print(request.encoding)
    # print(request.GET)
    # print(request.POST)
    # print(request.META)
    # 方法
    # print(request.get_host())
    # print(request.get_port())
    # print(request.get_full_path())
    # 响应 服务器回复给客户单的  响应封装对象
    # httpresponse = HttpResponse()
    # httpresponse.content = '测试响应信息'
    # httpresponse.content = '{"name":"devops","job":"linux"}'
    # httpresponse.content_type = 'application/json'
    # httpresponse.status_code = 500
    # return httpresponse
    # return HttpResponse('这是devops页面')
    # return HttpResponse('{"name":"devops","job":"linux"}',content_type="application/json")
    return JsonResponse({"name": "devops", "job": "linux"})


def testget(request):
    # 接收参数
    # print(request.GET)
    # get getlist 获取单个key
    # 获取单个数据 key对应一个value
    # print(request.GET.get('a'))
    # 获取多个数据 key对应多个value
    # print(request.GET.getlist('a'))
    # items 返回多个key 单个value对应的元组结构
    for i in request.GET.items():
        print(i)
    # lists 反馈多个key 如果一个key对应多个value 也可以获取到  元组结构
    for i in request.GET.lists():
        print(i)
    # lists
    # 返回参数信息
    return HttpResponse(
        '测试get请求方法参数为a:{},b:{},c:{}'.format(request.GET.get('a'), request.GET.get('b'), request.GET.get('c')))


def testpost(request):
    print(request.POST)
    return HttpResponse(
        '测试post请求方法参数为a:{},b:{},c:{}'.format(request.POST.get('a'), request.POST.get('b'), request.POST.get('c')))


def ad(request):
    # return HttpResponse('广告页面测试')
    return render(request, 'ad.html')


def ad1(request):
    return HttpResponse('ad1方法')


def testurl(request,year,month,day):
    print(year,month,day)
    return HttpResponse('{}年{}月{}日'.format(year,month,day))
